import logging

import pytest
import requests
class TestY():
    token=None
    def test_dl(self):
        url='http://10.59.9.12:7001/api/public/login'
        data={"username":"13811033962","password":"123456"}
        r = requests.post(url=url, json=data)
        TestY.token = "Bearer " + r.json()['data']['token']
        print(r.json())
        logging.info(r.json())
        assert r.status_code==200
        #查看商品详情
    def test_xiangqing(self):
        url='http://10.59.9.12:7001/api/goods/view?id=33'
        headers={"auth-token":TestY.token}
        r=requests.get(url=url,headers=headers)
        print(r.json())
        logging.info(r.json())
        assert "info" in r.text
        #加入购物车接口
    def test_jiaru(self):
        url='http://10.59.9.12:7001/api/cart/add'
        data={"id":33,"sku_id":"","num":1}
        headers = {"auth-token": TestY.token}
        r=requests.post(url=url,json=data,headers=headers)
        print(r.json())
        logging.info(r.json())
        assert "商品添加至购物车成功" in r.text
        #确定订单接口
    def test_queren(self):
        url='http://10.59.9.12:7001/api/order/confirm?id=46&type=cart&shipping_type=1'
        headers = {"auth-token": TestY.token}
        r = requests.get(url=url, headers=headers)
        print(r.json())
        logging.info(r.json())
        assert "info" in r.text

    def test_tijiao(self):
        url='http://10.59.9.12:7001/api/order/create'
        data={"id":"33","type":"buy","address_id":15,"store_id":1,"shipping_type":1,"bonus_id":"0","payment":"balance","remarks":"","source":1,"url":"http://10.59.9.12:7001/wap/pages/cart/confirm?id=33&sku_id=&num=1&type=buy","sku_id":"","num":"1"}
        headers = {"auth-token": TestY.token}
        r = requests.post(url=url, json=data, headers=headers)
        print(r.json())
        logging.info(r.json())
        assert "支付成功" in r.text

